package sf.database.jdbc.sql;

import sf.dynamicsql.DynmicSQLImpl;
import sf.dynamicsql.DynmicSQLInf;
import sf.dynamicsql.DynmicSQLModelImpl;
import sf.dynamicsql.DynmicSQLModelInf;
import sf.jooq.JooqImpl;
import sf.jooq.JooqInf;
import sf.querydsl.QueryDSLInf;
import sf.querydsl.QueryDSLOrmImpl;

/**
 * 基础sql封装类
 * @author sxf
 */
public class Crud {
    private static Crud c = new Crud();

    private final CrudSqlInf crudSql = CrudSqlImpl.getInstance();

    private final CrudTemplateInf crudTemplate = CrudTemplateImpl.getInstance();

    private final CrudModelInf crudModel = CrudModelImpl.getInstance();

    private final CrudExampleInf crudExample = CrudExampleImpl.getInstance();

    private volatile QueryDSLInf queryDSLInf;

    private volatile JooqInf jooqInf;

    private volatile DynmicSQLInf dynmicSQLInf;

    private volatile DynmicSQLModelInf dynmicSQLModelInf;

    private Crud() {

    }

    public static Crud getInstance() {
        return c;
    }

    /**
     * 直接对sql操作
     * @return
     */
    public CrudSqlInf getCrudSql() {
        return crudSql;
    }

    /**
     * 直接对模板sql操作
     * @return
     */
    public CrudTemplateInf getCrudTemplate() {
        return crudTemplate;
    }

    public CrudModelInf getCrudModel() {
        return crudModel;
    }

    public CrudExampleInf getCrudExample() {
        return crudExample;
    }

    /**
     * 获取dsljdbc的接口
     * @return
     */
    public QueryDSLInf getQueryDSLInf() {
        if (queryDSLInf == null) {
            queryDSLInf = QueryDSLOrmImpl.getInstance();
        }
        return queryDSLInf;
    }

    public JooqInf getJooqInf() {
        if (jooqInf == null) {
            jooqInf = JooqImpl.getInstance();
        }
        return jooqInf;
    }

    public DynmicSQLInf getDynmicSQLInf() {
        if (dynmicSQLInf == null) {
            dynmicSQLInf = DynmicSQLImpl.getInstance();
        }
        return dynmicSQLInf;
    }

    public DynmicSQLModelInf getDynmicSQLModelInf() {
        if (dynmicSQLModelInf == null) {
            dynmicSQLModelInf = DynmicSQLModelImpl.getInstance();
        }
        return dynmicSQLModelInf;
    }
}
